<?php

class OrderController extends BaseController {
    
	    public function getList($shop_id){
	        
	        try{
	        
	         echo json_encode(Orders::Select($shop_id));

	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        } 
	        
	    }
     	public function postInsert(){
	    	//checks the information input
		    try{
			    $input=Input::json()->all();

	            $shop_id=InputHelper::getInput($input,'shop_id');

	            $order_number=InputHelper::getInput($input,'order_number');

	            $address=InputHelper::getInput($input,'warehouse_id');

	            $total_money=InputHelper::getInput($input,'total_money','');

	            $user_id=InputHelper::getInput($input,'user_id','');

	            $status=InputHelper::getInput($input,'status','');

	            $good_id=InputHelper::getInput($input,'good_id','');

	            $number=InputHelper::getInput($input,'number','');

	            $import_price=InputHelper::getInput($input,'import_price','');

	            $tax=InputHelper::getInput($input,'tax','');

	            $discount=InputHelper::getInput($input,'discount','');

	            $comments=InputHelper::getInput($input,'comments','');
	        }catch(Exception $e){
	        	return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		    try{

		    	$input = Input::all();
		    	
		    	if($order_id = Orders:: Insert($input))
	        	{
                	return Response::json(array('status'=>'success','order_id'=>$order_id));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
        
        
        public function postEdit(){
	    	//checks the information input
		    try{
			    $input=Input::json()->all();

	            $order_id=InputHelper::getInput($input,'order_id');

	            $order_number=InputHelper::getInput($input,'order_number');

	            $address=InputHelper::getInput($input,'warehouse_id');

	            $total_money=InputHelper::getInput($input,'total_money','');

	            $user_id=InputHelper::getInput($input,'user_id','');

	            $status=InputHelper::getInput($input,'status','');

	            $good_id=InputHelper::getInput($input,'good_id','');

	            $number=InputHelper::getInput($input,'number','');

	            $import_price=InputHelper::getInput($input,'import_price','');

	            $tax=InputHelper::getInput($input,'tax','');

	            $discount=InputHelper::getInput($input,'discount','');

	            $comments=InputHelper::getInput($input,'comments','');
	        }catch(Exception $e){
	        	return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		    try{

		    	if(Orders:: Edit($order_number, $warehouse_id, $total_money, $user_id, $status,$order_id,$good_id,$number,$import_price,$tax,$discount ,$comments))
	        	{
                	return Response::json(array('status'=>'success'));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}  
        public function postDelete(){
        	try{
			    $input=Input::json()->all();
			    $order_id=InputHelper::getInput($input,'order_id');
			}catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	            
	        try{
	        	if(Orders::Del($order_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }
	    
	    public function postUpdateStatus(){
	    	try{
			    $input=Input::json()->all();
			    $order_id=InputHelper::getInput($input,'order_id');
			    $status=InputHelper::getInput($input,'status');
			}catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    	
	    	try{
	    		if(Orders::UpStatus($order_id,$status))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}
	    	}
	    	catch(Exception $e){
	    		return ErrorResponse::SendErrorMessage($e->getMessage());
	    	}
	    }
                        
}
      